import express from 'express';
import db from '../models/db.js';

const router = express.Router();


router.get('/testdb', (req, res) => {
    db.prepare(`INSERT INTO data (temperature, humidity) VALUES (?, ?)`).run(25.5, 60.5);
    const data = db.prepare(`SELECT * FROM data`).all();
    res.send(data);
})

router.get('/list', (req, res) => {
    res.send([
        { id: 1, name: '环境监测A区' },
        { id: 2, name: '环境监测B区' },
        { id: 3, name: '环境监测C区' },
        { id: 4, name: '环境监测D区' },
    ])
});

// /{id}/his
router.get('/:id/his', (req, res) => {
    const id = req.params.id;
    res.send({
        id,
        temperature: [25.5,24.5,23.5,22.5,21.5,20.5,19.5],
        humidity: [60.5,61.5,62.5,63.5,64.5,65.5,66.5],
        co2: [500,600,700,800,900,1000,1100],
        created_at: new Date()
    })
})

// /{id}
router.get('/:id', (req, res) => {
    res.send({
        id: req.params.id,
        temperature: 25.5,
        humidity: 60.5,
        co2: 500,
        lig: 1000,
        Dfan: 0,
        Dlig: 0,
        Dala: 0
    })
})

router.post('/:id', (req, res) => {
    res.send({
        statr: 'ok'
    })
})

export default router;
